package com.jfs.health;

import com.jfs.entity.Device;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Description 注册设备列表
 * @E-mail cwm3412638@163.com
 * @Author cwm
 * @Date 2022-08-23
 */
public class RegistryDevice {
    /**
     * 设备注册列表
     */
    private static final Map<String, Device> DEVICES = new ConcurrentHashMap<>();

    /**
     * 注册设备
     */
    public static void registry(Device device) {
        DEVICES.put(device.getDeviceId(),device);
    }

    /**
     * 移除设备到注册表中
     *
     * @param key
     */
    public static void remove(String key) {
        if (DEVICES.containsKey(key)) {
            DEVICES.remove(key);
        }
    }

    /**
     * 获取设备
     *
     * @param key
     * @return
     */
    public static Device get(String key) {
        if (DEVICES.containsKey(key)) {
            return DEVICES.get(key);
        }
        return null;
    }
}
